package rexsee.core.application;

import rexsee.core.browser.Browser;
import rexsee.core.browser.clazz.JavascriptInterface;

public class RexseeInterfaceManager implements JavascriptInterface {

	public static final String INTERFACE_NAME = "InterfaceManager";
	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return new RexseeInterfaceManager(childBrowser);
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return new RexseeInterfaceManager(childBrowser);
	}

	private final Browser mBrowser;

	public RexseeInterfaceManager(Browser browser) {
		mBrowser = browser;
	}

	//JavaScript Interface
	public int size() {
		return mBrowser.interfaceList.size();
	}
	public String get() {
		return mBrowser.interfaceList.get();
	}
	public boolean exists(String interfaceName) {
		return mBrowser.interfaceList.contains(interfaceName);
	}
	public boolean isInherit(String interfaceName) {
		return mBrowser.interfaceList.isInherit(interfaceName);
	}
	public int sizeOfCreations() {
		return mBrowser.interfaceList.sizeOfCreations();
	}
	public String getCreations() {
		return mBrowser.interfaceList.getCreations();
	}

	//The following functions will be effective only after refreshed the page or went to another page
	public void remove(String interfaceName) {
		mBrowser.interfaceList.remove(interfaceName);
	}

	public boolean create(String interfaceName, String shortcut) {
		return mBrowser.interfaceList.create(interfaceName, shortcut);
	}

	public boolean createFromParent(String interfaceName, String shortcut) {
		return mBrowser.interfaceList.createFromParent(interfaceName, shortcut);
	}
	public boolean createShortcutFromParent(String interfaceName, String shortcut) {
		return mBrowser.interfaceList.createShortcutFromParent(interfaceName, shortcut);
	}

}
